import 'package:flutter/material.dart';
import 'package:flutter_country_website/views/about_page.dart';
import 'package:flutter_country_website/views/home.dart';
import 'package:flutter_country_website/views/news_page.dart';
import 'package:flutter_country_website/views/scenic_page.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter City',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomeView(),
    );
  }
}

class HomeView extends StatefulWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  State<HomeView> createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {

  PageController pageController = PageController();
  int bottomIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFFf9f9f9),
      body: pageBody(),
      bottomNavigationBar: SalomonBottomBar(
        currentIndex: bottomIndex,
        onTap: (index) {
          setState(() {
            bottomIndex = index;
            pageController.animateToPage(index, duration: Duration(milliseconds: 500), curve: Curves.ease);
          });
        },
        items: [
          /// Home
          SalomonBottomBarItem(
            icon: Icon(Icons.home),
            title: Text("首页"),
            selectedColor: Colors.purple,
          ),

          /// Likes
          SalomonBottomBarItem(
            icon: Icon(Icons.favorite_border),
            title: Text("景点"),
            selectedColor: Colors.pink,
          ),

          /// Search
          SalomonBottomBarItem(
            icon: Icon(Icons.search),
            title: Text("趣闻"),
            selectedColor: Colors.orange,
          ),

          /// Profile
          SalomonBottomBarItem(
            icon: Icon(Icons.person),
            title: Text("关于我们"),
            selectedColor: Colors.teal,
          ),
        ],
      ),
    );
  }

  Widget pageBody() {
    return PageView(
      controller: pageController,
      onPageChanged: (int index) {
        setState(() {
          bottomIndex = index;
        });
      },
      children: [
        HomePage(),
        ScenicPage(),
        NewsPage(),
        AboutPage()
      ],
    );
  }

}


